package initialize

import (
	"fmt"
	"github.com/nacos-group/nacos-sdk-go/v2/clients"
	"github.com/nacos-group/nacos-sdk-go/v2/common/constant"
	"github.com/nacos-group/nacos-sdk-go/v2/vo"
	"os"
)

type NoaCos struct {
	Kong   string "2c3c14b2-608b-464e-afec-24683a70b6cd"
	DataId string "yuanxiaoliang"
	Group  string "DEFAULT_GROUP"
	Host   string "1.94.42.54"
	Port   int64
}

func InitNaCos() {
	App := NoaCos{
		Kong:   "2c3c14b2-608b-464e-afec-24683a70b6cd",
		DataId: "yuanxiaoliang",
		Group:  "DEFAULT_GROUP",
		Host:   "1.94.42.54",
		Port:   8848,
	}
	os.Mkdir("./tmp/nacos/log", 0777)
	os.Mkdir("./tmp/nacos/cache", 0777)

	//create clientConfig
	clientConfig := constant.ClientConfig{
		NamespaceId:         App.Kong, //we can create multiple clients with different namespaceId to support multiple namespace.When namespace is public, fill in the blank string here.
		TimeoutMs:           5000,
		NotLoadCacheAtStart: true,
		LogDir:              "/tmp/nacos/log",
		CacheDir:            "/tmp/nacos/cache",
		LogLevel:            "debug",
	}

	serverConfigs := []constant.ServerConfig{
		{
			IpAddr:      App.DataId,
			ContextPath: "/nacos",
			Port:        uint64(App.Port),
			Scheme:      "http",
		},
		{
			IpAddr:      "console2.nacos.io",
			ContextPath: "/nacos",
			Port:        uint64(App.Port),
			Scheme:      "http",
		},
	}
	// Another way of create naming client for service discovery (recommend)
	namingClient, err := clients.NewNamingClient(
		vo.NacosClientParam{
			ClientConfig:  &clientConfig,
			ServerConfigs: serverConfigs,
		},
	)

	// Another way of create config client for dynamic configuration (recommend)
	configClient, err := clients.NewConfigClient(
		vo.NacosClientParam{
			ClientConfig:  &clientConfig,
			ServerConfigs: serverConfigs,
		},
	)
	if err != nil {
		fmt.Println("连接失败")
		return
	}
	fmt.Println(namingClient)
	fmt.Println(configClient)
}
